package util;

import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.util.StringUtils;

import java.lang.reflect.Method;

/**
 * Spring缓存的key生成器
 */
public class MethodIncludedKeyGenerator implements KeyGenerator {
    @Override
    public Object generate(Object target, Method method, Object... params) {
        StringBuilder key = new StringBuilder();
        key.append(method.getName());//添加方法名

        if (params.length > 0) {
            key.append("-").append(StringUtils.arrayToDelimitedString(params, "-"));
        }

        return key.toString();
    }
}
